package com.weijian.dal.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 任务状态枚举
 */
@Getter
public enum TaskStatus {

    /**
     * 待运行
     */
    PENDING(0, "待运行"),

    /**
     * 运行中
     */
    RUNNING(1, "运行中"),

    /**
     * 成功
     */
    SUCCESS(2, "成功"),

    /**
     * 失败
     */
    FAILED(3, "失败");

    @EnumValue
    private final int code;
    @JsonValue
    private final String description;

    TaskStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据编码获取任务状态
     *
     * @param code 状态编码
     * @return 任务状态枚举，如果未找到返回null
     */
    public static TaskStatus fromCode(int code) {
        for (TaskStatus status : TaskStatus.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }
}